import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';

export const movieSLice = createSlice({
    name: 'movie',
    initialState: {
        list: [],
        totals: 0,
    },
    reducers: {
        loadDataEnd(state, { payload }) {
            state.list = payload;
            state.totals = payload.length;
        },
    },
    // 可以额外的触发其他slice中的数据关联改变
    extraReducers: {
        [loadData.fulfilled](state, { payload }) {
            console.log(payload);
            state.list = payload.data.list;
        },
        [loadData.rejected](state, err) {
            console.log(err);
        },
        [loadData.pending](state) {
            console.log('进行中');
        },
    },
});

export const { loadDataEnd } = movieSLice.actions;
export default movieSLice.reducer;